package com.example.guide.validdata;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Map;

/**
 *
 * @author Administrator
 */
@Slf4j
@RestController
@RequestMapping("test")
@Validated
public class TestController {

    @PostMapping("testEntityValidated")
    public ResponseEntity testValidated2(@Valid @RequestBody ValidTest validTest) {
        log.info("slf4j");
       // validTest.setJoinDate(LocalDateTime.now().plusDays(1));
        return ResponseEntity.ok(validTest);
    }

    @GetMapping("testSingleValidated")
    public ResponseEntity testValidated(@RequestParam("param") @NotNull(message = "参数不能为空") String param) {
        log.info("testSingleValidated");
        return ResponseEntity.ok(param);
    }

    @PostMapping("testMap")
    public ResponseEntity testMap( @RequestBody Map param) {
        param.put("sid", LocalDateTime.now());
        return ResponseEntity.ok(param);
    }

    @PostMapping("testPar")
    public ResponseEntity testMap( @CustomParam String param) {
       log.info(param);
        return ResponseEntity.ok(param);
    }


}
